package cn.darkhorse.mesadmin.controller.ticket;


import cn.darkhorse.ticket.code.RepeatCheck;
import cn.darkhorse.ticket.constants.TicketConstants;
import cn.darkhorse.ticket.production.dto.TicketInfoDTO;
import cn.darkhorse.ticket.production.pojo.TicketInfo;
import cn.darkhorse.ticket.production.service.TicketInfoService;
import cn.darkhorse.ticket.production.vo.TicketInfoVO;
import cn.darkhorse.ticket.production.vo.TicketInfoViewVO;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 工单管理 前端控制器
 * </p>
 *
 * @author maoguanjun
 * @since 2024-01-30
 */
@RestController
@RequestMapping("/ticketproduction/ticketInfo")
public class TicketInfoController extends BaseController {
    @Resource
    private TicketInfoService infoService;
    @Resource
    private RepeatCheck<TicketInfo> repeatCheck;

    /**
     * 列表
     * @param dto
     * @return
     */
    @RequestMapping("/list")
    public TableDataInfo list(TicketInfoDTO dto){
        startPage();
        List<TicketInfoVO> list=infoService.listAll(dto);
        return getDataTable(list);
    }

    /**
     * 保存
     * @param vo
     * @return
     */
    @RequestMapping("/save")
    public AjaxResult save(@Validated @RequestBody TicketInfoVO vo){
        //编码校验
        repeatCheck.repeatCode(infoService,vo, TicketConstants.BUSINESS_TYPE_GD);
        boolean result=infoService.saveTicket(vo);
        return AjaxResult.success(result);
    }

    /**
     * 查看
     * @param dataId
     * @return
     */
    @RequestMapping("/view")
    public AjaxResult view(Long dataId){
        if(null==dataId){
            return AjaxResult.error("缺失参数");
        }
        TicketInfoViewVO vo=infoService.view(dataId);
        return AjaxResult.success(vo);
    }


    /**
     * 开始校验 true可以开始false不能开始
     * @param dataId
     * @return
     */
    @RequestMapping("/start-check")
    public AjaxResult startCheck(Long dataId){
        if(null==dataId){
            return AjaxResult.error("缺失参数");
        }
        boolean result=infoService.startCheck(dataId);
        return AjaxResult.success(result);
    }

    /**
     * 开始
     * @param dataId
     * @return
     */
    @RequestMapping("/start")
    public AjaxResult start(Long dataId){
        if(null==dataId){
            return AjaxResult.error("缺失参数");
        }
        boolean result=infoService.start(dataId);
        return AjaxResult.success(result);
    }

    /**
     * 结束校验 true存在未完成任务 false不存在未完成任务
     * @param dataId
     * @return
     */
    @RequestMapping("/end-check")
    public AjaxResult endCheck(Long dataId){
        if(null==dataId){
            return AjaxResult.error("缺失参数");
        }
        boolean result=infoService.endCheck(dataId);
        return AjaxResult.success(result);
    }
    /**
     * 结束
     * @param dataId
     * @return
     */
    @RequestMapping("/end")
    public AjaxResult end(Long dataId){
        if(null==dataId){
            return AjaxResult.error("缺失参数");
        }
        boolean result=infoService.end(dataId);
        return AjaxResult.success(result);
    }
    /**
     * 取消
     * @param dataId
     * @return
     */
    @RequestMapping("/cancel")
    public AjaxResult cancel(Long dataId){
        if(null==dataId){
            return AjaxResult.error("缺失参数");
        }
        boolean result=infoService.cancel(dataId);
        return AjaxResult.success(result);
    }
}

